function getType(x) {
	// If x is null, return "null"
	if (x == null)
		return "null";
	// Next try the typeof operator
	var t = typeof x;
	// If the result is not vague, return it
	if (t != "object")
		return t;
	// Otherwise, x is an object. Use the default toString( ) method to
	// get the class value of the object.
	var c = Object.prototype.toString.apply(x); // Returns "[object class]"
	c = c.substring(8, c.length - 1); // Strip off "[object" and "]" // If the class is not a vague one, return it.
	if (c != "Object")
		return c;
	// If we get here, c is "Object". Check to see if
	// the value x is really just a generic object.
	if (x.constructor == Object)
		return c; // Okay the type really is "Object"
		
	// For user-defined classes, look for a string-valued property named
	// className, that is inherited from the object's prototype
	if ("className" in x.constructor.prototype && // inherits className
			typeof x.constructor.prototype.className == "string") // its a string
		return x.constructor.prototype.className;
	// If we really can't figure it out, say so.
	return "<unknown type>";
}

var d = new Date();
alert(getType(d));

var o = new Object();
alert(getType(o));

function Person() {}
Person.prototype.className = 'Person';

var p = new Person();
alert(getType(p));


